/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package battleshipgame.ui;
import Excersize2_Swing.SwingConstants.BattleshipTypes;
import battleshipgame.logic.Battleship;
import battleshipgame.logic.InvalidInputException;
import battleshipgame.logic.Player;
import battleshipgame.manager.GameManager;
import battleshipgame.manager.XmlHandler;

/**
 *
 * @author dunay
 */
public class WebIOManualInputHandler {
        public static void getGameDataFromUser(GameManager gameManager) throws InvalidInputException
        {
            if(gameManager.currentUserInput == WebIOManager.UserInputType.MANUAL_INPUT)
            {
                gameManager.currentState = WebIOManager.SessionState.MANUAL_INPUT_STATE;
            }
            else if(gameManager.currentUserInput == WebIOManager.UserInputType.ADD_PLAYER)
            {
                Player player = new Player(gameManager.playerNameToAdd,gameManager.players.size(),gameManager.currentPlayerType, gameManager);
                gameManager.addPlayer(player);
                gameManager.currentPlayer = player;
            }
            else if(gameManager.currentUserInput == WebIOManager.UserInputType.ADD_BATTLESHIP)
            {
                int i;
                for(i=0; i<Battleship.battleShipNamesList.length; i++)
                {
                    if(Battleship.battleShipNamesList[i].equals(gameManager.battleshipNameToAdd))
                    {
                        break;
                    }
                }

                try
                {
                Battleship battleship = new Battleship(Battleship.battleShipNamesList[i], Battleship.battleShipSizeList[i]);
                gameManager.currentPlayer.SetBattleshipInBoard(
                        battleship,
                        gameManager.coordinateSelected,
                        gameManager.battleshipDirectionToAdd);
                }
                catch(InvalidInputException e)
                {
                    gameManager.currentWebIOManager.printException(e);
                }
            }
            if(gameManager.currentUserInput == WebIOManager.UserInputType.SELECT_PLAYER)
            {
                // only refresh screen
                ;
            }



            if(gameManager.currentUserInput == WebIOManager.UserInputType.INIT_GAME_FINISHED)
            {
                // save content to backup xml
                //start the game
                XmlHandler.saveGameDataToXml(gameManager,"backup.xml");
                gameManager.currentState = WebIOManager.SessionState.IN_GAME_WAIT_FOR_USER_INPUT;
                
            }
            else
            {
                gameManager.currentWebIOManager.printManualInit(gameManager.currentPlayer);
            }

            
        }
}
